﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Win32;

namespace 自动压缩备份
{
    public partial class MainForm : Form
    {
        //窗体是否显示
        bool FormVisible = true;

        //记录备份目录
        ArrayList selectpathlist = new ArrayList();

        //自动备份时间点
        DateTime backuptime = DateTime.MinValue;
        //自动删除时间间隔天数
        int deletedays = 0;
        string deletedaysstr = "";
        //是否开机启动
        bool isstartrun = false;
        //是否自动删除
        bool isontimedelete = false;
        //是否自动备份
        bool isontimebackup = false;
        //是否启动隐藏界面
        bool ishideform = false;

        public MainForm()
        {
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
            //this.TopMost = true;

            //实现启动不显示界面（放到窗体未加载完成之前，不会出现闪烁）
            this.ShowInTaskbar = false;
            this.WindowState = FormWindowState.Minimized;
            FormVisible = false;

            InitializeComponent();


            //comboxDeleteTime.SelectedIndex = 0;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            init();
        }

        //是否正在执行备份
        bool IsRun = false;

        /// <summary>
        /// 加载配置信息
        /// </summary>
        void init()
        {
            string savepath = Properties.Settings.Default.SavePath.ToString();
            string selectpath1 = Properties.Settings.Default.selectPath1.ToString();
            string selectpath2 = Properties.Settings.Default.selectPath2.ToString();
            string selectpath3 = Properties.Settings.Default.selectPath3.ToString();
            string selectpath4 = Properties.Settings.Default.selectPath4.ToString();
            string selectpath5 = Properties.Settings.Default.selectPath5.ToString();
            string selectpath6 = Properties.Settings.Default.selectPath6.ToString();
            string selectpath7 = Properties.Settings.Default.selectPath7.ToString();
            string selectpath8 = Properties.Settings.Default.selectPath8.ToString();
            string selectpath9 = Properties.Settings.Default.selectPath9.ToString();

            if (savepath != "")
            {
                txtSavePath.Text = savepath;
            }

            if (selectpath1 != "")
            {
                txtselectPath1.Text = selectpath1;
                selectpathlist.Add(selectpath1);
            }
            if (selectpath2 != "")
            {
                txtselectPath2.Text = selectpath2;
                selectpathlist.Add(selectpath2);
            }
            if (selectpath3 != "")
            {
                txtselectPath3.Text = selectpath3;
                selectpathlist.Add(selectpath3);
            }
            if (selectpath4 != "")
            {
                txtselectPath4.Text = selectpath4;
                selectpathlist.Add(selectpath4);
            }
            if (selectpath5 != "")
            {
                txtselectPath5.Text = selectpath5;
                selectpathlist.Add(selectpath5);
            }
            if (selectpath6 != "")
            {
                txtselectPath6.Text = selectpath6;
                selectpathlist.Add(selectpath6);
            }
            if (selectpath7 != "")
            {
                txtselectPath7.Text = selectpath7;
                selectpathlist.Add(selectpath7);
            }
            if (selectpath8 != "")
            {
                txtselectPath8.Text = selectpath8;
                selectpathlist.Add(selectpath8);
            }
            if (selectpath9 != "")
            {
                txtselectPath9.Text = selectpath9;
                selectpathlist.Add(selectpath9);
            }

            isstartrun = Properties.Settings.Default.IsStartRun;
            isontimebackup = Properties.Settings.Default.IsOnTimeBackUp;
            isontimedelete = Properties.Settings.Default.IsOnTimeDelete;
            ishideform = Properties.Settings.Default.IsHideForm;
            //第一次启动时判断下是否启动隐藏界面(不隐藏就执行显示事件)
            if(!ishideform)
            {
                toolStripMenuItem5_Click(null,null);
            }

            string backuptimestr = Properties.Settings.Default.BackUpTime.ToString();
            if (backuptimestr != "")
            {
                backuptime = DateTime.Parse(backuptimestr);
            }

            deletedaysstr = Properties.Settings.Default.DeleteTime;
        }


        #region 设置备份目录
        private void btnSelect1_Click(object sender, EventArgs e)
        {
            //如果直接多次选择（未先清空操作），则需要处理缓存中的记录
            string oldpath = txtselectPath1.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath1.Text = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();
                Properties.Settings.Default.selectPath1 = fbd.SelectedPath;

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect2_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath2.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath2.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath2 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect3_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath3.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath3.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath3 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect4_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath4.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath4.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath4 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect5_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath5.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath5.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath5 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect6_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath6.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath6.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath6 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect7_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath7.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath7.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath7 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect8_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath8.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath8.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath8 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }

        private void btnSelect9_Click(object sender, EventArgs e)
        {
            string oldpath = txtselectPath9.Text.Trim();

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("该备份目录已存在");
                    return;
                }
                selectpathlist.Add(fbd.SelectedPath);
                txtselectPath9.Text = fbd.SelectedPath;
                Properties.Settings.Default.selectPath9 = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                if (oldpath != "")
                {
                    int index = selectpathlist.IndexOf(oldpath);
                    if (index > -1)
                    {
                        selectpathlist.RemoveAt(index);
                    }
                }
            }
        }
        #endregion

        #region 设置存储目录
        private void btnSave_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (selectpathlist.Contains(fbd.SelectedPath))
                {
                    MessageBox.Show("备份文件存储目录不能为选中的备份目录");
                    return;
                }
                txtSavePath.Text = fbd.SelectedPath;
                Properties.Settings.Default.SavePath = fbd.SelectedPath;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();
            }
        }
        #endregion

        #region 清理设置的目录
        private void btnClear_Click(object sender, EventArgs e)
        {
            txtSavePath.Text = "";
            Properties.Settings.Default.SavePath = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear1_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath1.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath1.Text = "";
            Properties.Settings.Default.selectPath1 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();


        }

        private void btnClear2_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath2.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath2.Text = "";
            Properties.Settings.Default.selectPath2 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear3_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath3.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath3.Text = "";
            Properties.Settings.Default.selectPath3 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear4_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath4.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath4.Text = "";
            Properties.Settings.Default.selectPath4 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear5_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath1.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath5.Text = "";
            Properties.Settings.Default.selectPath5 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear6_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath6.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath6.Text = "";
            Properties.Settings.Default.selectPath6 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear7_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath7.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath7.Text = "";
            Properties.Settings.Default.selectPath7 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear8_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath8.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath8.Text = "";
            Properties.Settings.Default.selectPath8 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }

        private void btnClear9_Click(object sender, EventArgs e)
        {
            //清理全局变量中的路径
            int index = selectpathlist.IndexOf(txtselectPath9.Text.Trim());
            if (index > -1)
            {
                selectpathlist.RemoveAt(index);
            }

            txtselectPath9.Text = "";
            Properties.Settings.Default.selectPath9 = "";
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Reload();
        }
        #endregion


        /// <summary>
        /// 开始备份
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartSave_Click(object sender, EventArgs e)
        {

            if (selectpathlist.Count == 0)
            {
                ShowMsg("请先设置需要备份的目录");
                return;
            }
            if (txtSavePath.Text.Trim() == "")
            {
                ShowMsg("请设置备份文件存储目录");
                return;
            }

            btnStartSave.Enabled = false;

            Func<string> dl = DoMain;
            dl.BeginInvoke(Completed, dl);

            this.Cursor = Cursors.WaitCursor;
        }

        /// <summary>
        /// 开始删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            btnDelete.Enabled = false;

            if (deletedays == 0)
            {
                ShowMsg("请先设置删除间隔时间");
                btnDelete.Enabled = true;
                return;
            }

            if (txtSavePath.Text.Trim() == "")
            {
                ShowMsg("请设置备份文件存储目录");
                btnDelete.Enabled = true;
                return;
            }

            DateTime datetimeold = DateTime.Now;
            //减去时间间隔
            datetimeold = datetimeold.AddDays(-deletedays);

            DirectoryInfo dirinfo = new DirectoryInfo(txtSavePath.Text.Trim());

            int num = 0;
            //文件夹内为空不处理
            if (dirinfo.GetFiles().Length > 0)
            {

                foreach (FileInfo fi in dirinfo.GetFiles())
                {
                    //删除间隔时间之前的文件
                    if (fi.CreationTime.CompareTo(datetimeold) < 0)
                    {
                        num++;
                        fi.Delete();
                    }
                }

                if (num > 0)
                {
                    ShowMsg("删除文件成功");
                }
                else
                {
                    ShowMsg("不存在需要删除的文件");
                }
            }

            btnDelete.Enabled = true;
        }

        /// <summary>
        /// 执行完成
        /// </summary>
        /// <param name="ar"></param>
        void Completed(IAsyncResult ar)
        {
            IsRun = false;
            btnStartSave.Enabled = true;
            this.Cursor = Cursors.Default;

            ShowMsg("备份已完成");
        }

        /// <summary>
        /// 提示备份信息
        /// </summary>
        /// <param name="msg"></param>
        void ShowMsg(string msg)
        {
            notifyIcon1.BalloonTipTitle = "提示";
            notifyIcon1.BalloonTipText = msg;
            notifyIcon1.ShowBalloonTip(3000);
        }

        /// <summary>
        /// 执行备份
        /// </summary>
        /// <returns></returns>
        string DoMain()
        {
            foreach (string path in selectpathlist)
            {
                SaveZipFile(path);
            }

            return "";
        }

        /// <summary>
        /// 压缩备份方法
        /// </summary>
        /// <param name="path"></param>
        void SaveZipFile(string path)
        {
            if (Directory.Exists(path))
            {
                string ZipFileName = new DirectoryInfo(path).Name + "(" + DateTime.Now.ToString("yyyy-MM-ddmmssfff") + ")" + ".zip";
                string SavePath = txtSavePath.Text.Trim() + "\\" + ZipFileName;

                using (FileStream ZipFile = File.Create(SavePath))
                {
                    using (ZipOutputStream s = new ZipOutputStream(ZipFile))
                    {
                        //压缩加密密码
                        if (false)
                        {
                            s.Password = "";
                        }

                        ZipSetp(path, s, "");
                    }
                }

            }
        }

        /// <summary>
        /// 递归遍历目录
        /// </summary>
        private static void ZipSetp(string strDirectory, ZipOutputStream s, string parentPath)
        {
            if (strDirectory[strDirectory.Length - 1] != Path.DirectorySeparatorChar)
            {
                strDirectory += Path.DirectorySeparatorChar;
            }
            Crc32 crc = new Crc32();

            string[] filenames = Directory.GetFileSystemEntries(strDirectory);

            foreach (string file in filenames)// 遍历所有的文件和目录
            {

                if (Directory.Exists(file))// 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                {
                    string pPath = parentPath;
                    pPath += file.Substring(file.LastIndexOf("\\") + 1);
                    pPath += "\\";
                    ZipSetp(file, s, pPath);
                }

                else // 否则直接压缩文件
                {
                    //打开压缩文件
                    using (FileStream fs = File.OpenRead(file))
                    {

                        byte[] buffer = new byte[fs.Length];
                        fs.Read(buffer, 0, buffer.Length);

                        string fileName = parentPath + file.Substring(file.LastIndexOf("\\") + 1);
                        ZipEntry entry = new ZipEntry(fileName);

                        entry.DateTime = DateTime.Now;
                        entry.Size = fs.Length;

                        fs.Close();

                        crc.Reset();
                        crc.Update(buffer);

                        entry.Crc = crc.Value;
                        s.PutNextEntry(entry);

                        s.Write(buffer, 0, buffer.Length);
                    }
                }
            }
        }


        /// <summary>
        /// 判断定时备份操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerBackUp_Tick(object sender, EventArgs e)
        {
            //2017年9月18日10:09:31 调整自动删除为每天执行一次，否则提示过于频繁
            if (!IsRun && DateTime.Now.Hour == backuptime.Hour && DateTime.Now.Minute == backuptime.Minute)
            {
                //只有勾选了自动删除才执行
                if (isontimedelete)
                {
                    btnDelete_Click(null, null);
                }

                IsRun = true;
                btnStartSave_Click(null, null);
            }
        }

        /// <summary>
        /// 双击工具栏图标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            if (FormVisible)
            {
                this.Hide();
                FormVisible = false;
            }
            else
            {
                this.Show();
                //正常显示(最小化事件状态恢复)
                this.WindowState = FormWindowState.Normal;
                FormVisible = true;
            }
        }

        /// <summary>
        /// 最小化事件(实现最小化到工具栏)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 屏蔽无效时间 2017年10月11日16:34:40
        //private void Form1_Deactivate(object sender, EventArgs e)
        //{
        //    if (this.WindowState == FormWindowState.Minimized)
        //        this.Hide();
        //}

        /// <summary>
        /// 单击打开备份存储目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (txtSavePath.Text.Trim() == "")
            {
                ShowMsg("请设置备份文件存储目录");
                return;
            }
            if (!Directory.Exists(txtSavePath.Text))
            {
                ShowMsg("设置备份文件存储目录不存在，请检查后重试");
                return;
            }
            System.Diagnostics.Process.Start(txtSavePath.Text.Trim());
        }

        /// <summary>
        /// 单击显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            if (!FormVisible)
            {
                this.Show();
                FormVisible = true;
                //正常显示(最小化事件状态恢复)
                this.WindowState = FormWindowState.Normal;
            }
        }

        /// <summary>
        /// 单击隐藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            if (FormVisible)
            {
                this.Hide();
                FormVisible = true;
            }
        }

        /// <summary>
        /// 单击退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 单击关于
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            ShowMsg("哈哈哈，你想看什么啊？？？");
        }

        /// <summary>
        /// 打开设置界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkSetting_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SettingForm setform = new SettingForm(backuptime, deletedaysstr, isstartrun, isontimedelete, isontimebackup, ishideform);
            setform.StartPosition = FormStartPosition.CenterParent;
            setform.ShowDialog();
            //重新加载配置信息
            init();
        }
    }
}
